//
// Created by Mr.J on 2019/11/1.
//

#include <iostream>
#include <vector>
using namespace std;
int maxProfit(std::vector<int>& prices) {
    int profit = 0,min = INT_MAX;
    int a = INT_MAX,all = 0;
    for(short i=0;i<prices.size();i++){
        if(prices[i] < min)min = prices[i];
        else if(prices[i] - min > profit)profit = prices[i] - min;
        if(prices[i]<a)a=prices[i];
        else{
            all += prices[i] - a;
            a = prices[i];
        }
    }
    return max(profit,all);
};

int main(){
    std::vector<int>b = {7,6,4,3,1};

    cout<<maxProfit(b)<<std::endl;
    return 0;
}